<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="jquery.js"></script>
    <script>
        $(function(){
            $('#logup').on('click',function(event){
                event.preventDefault();

                $.ajax({
                    url:'logup',
                    method:'get',
                    dataType:'json',
                    data:{
                        username:$('#username').val(),
                        password:$('#password').val()
                    },
                    success(res){
                        console.log(res)
                        if(res.code){
                            alert('注册失败:'+res.msg)
                        }else{
                            alert('注册成功:'+res.msg)
                        }
                    },
                    error(err){
                        alert('网路错误')
                    }
                })
            })
            $('#login').on('click',function(event){
                event.preventDefault();

                $.ajax({
                    url:'login',
                    method:'get',
                    dataType:'json',
                    data:{
                        username:$('#username').val(),
                        password:$('#password').val()
                    },
                    success(res){
                        console.log(res)
                        if(res.code){
                            alert('注册失败:'+res.msg)
                        }else{
                            alert('注册成功:'+res.msg)
                        }
                    },
                    error(err){
                        alert('网路错误')
                    }
                })
            })
        })
    </script>
</head>
<body>
    <form action="">
        username:<input type="text" name="user" id="username"><br>
        password:<input type="password" name="user" id="password"><br>
        <input id="logup" type="button" value="注册">
        <input id="login" type="button" value="提交">

    </form>
</body>
</html>